const TokenKey = 'access_token'
const UserKey = 'user'

export function getToken() {
	return uni.getStorageSync(TokenKey)
}

export function setToken(token) {
	return uni.setStorageSync(TokenKey, token)
}
export function removeToken() {
	return uni.removeStorageSync(TokenKey)
}
export function getUserInfo(key) {
	const userStr = uni.getStorageSync(UserKey)
	if (!userStr) {
		return {}
	}
	const userObj = JSON.parse(userStr)
	if (!key) {
		return userObj
	} else {
		return userObj[key]
	}
}

export function setUserInfo(obj) {
	const objStr = JSON.stringify(obj)
	return uni.setStorageSync(UserKey, objStr)
}

export function removeUserInfo() {
	return uni.removeStorageSync(UserKey)
}